package com.nowcoder.community.entity;
/*
* 分页数据
* */
public class Page {

    private int current=1;

    private int limit=10;


    //一共多少条数据
    private int rows;
    //返回路径，用于复用链接
    private String path;

    public int getCurrent() {
       return current;
    }

    public void setCurrent(int current) {
        if(current>0) {
            this.current=current;
        }else{
            this.current=1;
        }
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        if(limit<=0 || limit>100){
            this.limit=10;
        }
        this.limit = limit;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getTotal() {
        if (rows%limit==0) {
            return rows/limit;
        }else{
            return rows/limit+1;
        }
    }

    public int getOffset() {
        return (current-1)*limit;
    }

    public int getFrom() {

        return current-2>1?current-2:1;
    }

    public int getTo() {
    int to = current+2;
    int total =getTotal();
        return to<total?to:total;
    }

}
